package com.xingguo.info;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.base.component.BaseAction;
import com.base.component.BaseHibernateDAO;
import com.opensymphony.xwork2.ModelDriven;

@Controller
public class InfoAction extends BaseAction implements ModelDriven<Info> {
	@Resource
	BaseHibernateDAO baseHibernateDAO;

	private Info info = new Info();

	@Override
	public Info getModel() {
		return info;
	}

	public String goToEdit() {
		Info editInfo = (Info) baseHibernateDAO.get(Info.class, info.getId());
		if (null == editInfo) {
			editInfo = new Info();
			editInfo.setId(info.getId());
		}
		return addAttr("editInfo", editInfo).forward("edit.jsp");
	}

	public String edit() {
		baseHibernateDAO.saveOrUpdate(info);
		return forward("success.jsp");
	}
}
